import { GlobalFunction } from "../base/GlobalFunction";
import { GlobalEvent } from "../base/GlobalEvent";
import { ConstData } from "../base/ConstData";

const {ccclass, property} = cc._decorator;

@ccclass
export default class swordFunc extends cc.Component {

    @property(cc.Node)
    partical:cc.Node = null;

    onLoad(){
        GlobalEvent.on(GlobalEvent.Event.swtichAttackMode, function(Event){
            Event ? this.enterAttackMode() : this.quitAttackMode();
        }.bind(this),this);
    }

    enterAttackMode(){
        this.node.getComponent("fllowFunc").setFllowItem(null);
        this.node.getComponent(cc.RigidBody).linearVelocity = cc.v2(0,0);
        var tween = new cc.Tween();
        tween.target(this.partical);
        tween.to(0.5, {scale: 1.2, color:cc.color(255,0,0), opacity:255}, null);
        tween.start();
    }

    quitAttackMode(){
        this.node.getComponent("fllowFunc").setFllowItem(GlobalFunction.getWorldMgr().getPlayer());
        var tween = new cc.Tween();
        tween.target(this.partical);
        tween.to(0.5, {scale: 1, color:cc.color(0,0,0), opacity:200}, null);
        tween.start();
    }
}
